# 进程对象及方法
import time
from multiprocessing import Process, current_process
import os


def task():
    # current_process
    # print(current_process().pid)
    # os.getpid() 查看当前进程pid
    # os.getppid() 查看父进程pid
    print('子进程的pid:', os.getpid())
    print('子进程的父亲进程pid:', os.getppid())
    time.sleep(30)


if __name__ == '__main__':
    p = Process(target=task)
    p.start()
    p.terminate()  # 让系统杀死当前进程
    time.sleep(1)
    print(p.is_alive())  # 判断进程是否存活
    print('主进程运行', os.getpid())
    print('主进程的父进程pid', os.getppid())
